<?php
	$cs=Yii::app()->clientScript;
	$baseUrl=$this->module->assetsUrl;
	$cs->registerScriptFile($baseUrl.'/js/category-edit.js',CClientScript::POS_END);
    $registerScript="var sUrl='".$this->createUrl('category/ajaxTemplateList')."';";
    $registerScript.="var sType='default';";
    $registerScript.="var sUploadUrl='".$this->createUrl('attachment/upload')."';";
	Yii::app()->getClientScript()->registerScript('registerScript',$registerScript,CClientScript::POS_HEAD);
?>
<div class="row">
    <div class="button-container mb10">
    	<?php echo Yii::app()->user->checkAccess('category|add')?CHtml::link('添加栏目',$this->createUrl('category/add' ,array('cate_type'=>1 ,'pid'=>$pid)),array('class'=>'button button-success')):'';?>
        <?php echo Yii::app()->user->checkAccess('category|add')?CHtml::link('添加单页面',$this->createUrl('category/add' ,array('cate_type'=>2,'pid'=>$pid)),array('class'=>'button')):'';?>
        <?php echo Yii::app()->user->checkAccess('category|add')?CHtml::link('添加外部栏目',$this->createUrl('category/add' ,array('cate_type'=>3,'pid'=>$pid)),array('class'=>'button ')):'';?>
    
    </div>
    <div id="tab">
        <ul>
          <li class="bui-tab-panel-item active"><a href="#">基本设置</a></li>
          <li class="bui-tab-panel-item"><a href="#">模板设置</a></li>
          <li class="bui-tab-panel-item"><a href="#">优化设置</a></li>
        </ul>
    </div>
    <?php $form=$this->beginWidget('CActiveForm', array(
        'id'=>'category-_form-form',
        'enableAjaxValidation'=>false,
        'enableClientValidation'=>false,
        'clientOptions'=>array(  
            'validateOnSubmit'=>false,  
         ),
         'htmlOptions'=>array('class'=>'form-horizontal')
    )); ?>
    <div id="panel" class="" style="width: 100%; border:1px solid #ccc;">
        <div id="p1" class="mt10">
            <div class="control-group">
                <label class="control-label"><?php echo $this->_attributeLabels['model_id'] ?><span class="required">*</span>：</label>
                <div class="controls">
                  <?php 
                  if( isset($this->oModel->model_id) && $this->oModel->model_id ){
                    echo $form->dropDownList($this->oModel ,'model_id',CmsModel::getAllModelList(),array('class'=>'input-normal','disabled'=>true));
                    echo $form->hiddenField($this->oModel ,'model_id');  
                  } else {
                    echo $form->dropDownList($this->oModel,'model_id' ,CmsModel::getAllModelList() ,array('data-rules'=>"{required:true}",'data-messages'=>"{required:'模型不能为空'}",'class'=>'input-normal'));
                  }
                  ?>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label"><?php echo $this->_attributeLabels['parent_id'] ?><span class="required">*</span>：</label>
                <div class="controls">
                    <select name="AdminCategory[parent_id]" class="input-normal">
                    <option value="0">顶级栏目</option>
                    <?php 
                    $menuData = AdminCategory::getCategoryData();
                    $tree = new Tree($menuData);
                    $tree->icon = array('&nbsp;│ ','&nbsp;├─ ','&nbsp;└─ ');
                    $tree->nbsp = '&nbsp;';
                    $str="<option value='\$id' \$selected>\$spacer\$cate_name</option>";
                    $categorys = $tree->get_tree(0, $str, $pid);
                    echo $categorys;
                    ?>
                    </select>     
                  <?php //echo $form->textField($this->oModel,'model_id' ,array('data-rules'=>"{required:true}",'data-messages'=>"{required:'模型名称不能为空'}",'class'=>'input-large')); ?>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label"><?php echo $this->_attributeLabels['cate_name'] ?><span class="required">*</span>：</label>
                <div class="controls">
                  <?php echo $form->textField($this->oModel,'cate_name' ,array('data-rules'=>"{required:true}",'data-messages'=>"{required:'栏目名称不能为空'}",'class'=>'input-normal')); ?>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label"><?php echo $this->_attributeLabels['cate_image'] ?>：</label>
                <div class="controls control-row-auto">
                    <div id="J_Uploader"></div>
                    <?php
                    if( isset($this->oModel->cate_image) && $this->oModel->cate_image){
                        //之前有
                         echo '<input type="hidden" value="'.$this->oModel->cate_image.'" name="old[cate_image]" />';
                    ?>
                    <div class="bui-uploader imageViewTheme content-upload-cate-image">
                        <div class="bui-queue bui-simple-list">
                            <ul>
                                <li class="bui-queue-item bui-queue-item-success">
                                    <div class="success" style="width:240px;">
                                        <img src="<?php echo $this->oModel->cate_image ?>" width="240"> 
                                        <input type="hidden" value="<?php echo $this->oModel->cate_image ?>" name="AdminCategory[cate_image]" />
                                    </div> 
                                    <span class="action"><span class="bui-queue-item-del content-upload-delete-cate-image">删除</span></span>
                                </li>
                            </ul>
                        </div>
                    </div>                    
                    <?php
                    }
                    ?>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label"><?php echo $this->_attributeLabels['description'] ?>：</label>
                <div class="controls control-row-auto">
                  <?php echo $form->textarea($this->oModel,'description' ,array('class'=>'control-row4 input-large')); ?>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label"><?php echo $this->_attributeLabels['isnave'] ?><span class="required">*</span>：</label>
                <div class="controls">
                  <input type="hidden" value="<?php echo $iCateType; ?>" name="AdminCategory[cate_type]" /> 
                  <?php echo $form->radioButtonList($this->oModel,'isnave' ,Yii::app()->dict->get('category' ,'isnave') ,array('separator'=>'&nbsp;')); ?>
                </div>
            </div>
        </div>
        <div id="p2" class="mt10">            
            <div class="control-group">
                <label class="control-label"><?php echo $this->_attributeLabels['default_style'] ?>：</label>
                <div class="controls">
                    <select class="selectTemplate" name="setting[default_style]">
                        <?php                      
                        
                        foreach( $aTemplateList as $sKey=>$sVal ){
                            $selected = (isset($setting['default_style']) &&  $setting['default_style']==$sKey) ? 'selected' : '';
                            echo "<option value='$sKey' $selected>$sVal<ption>";
                        }
                        ?>
                    </select>                     
                </div>
            </div>
            <div class="control-group">
                <label class="control-label"><?php echo $this->_attributeLabels['category_template'] ?>：</label>
                <div class="controls categoryTemplate">
                    <?php 
                    $style = isset($setting['default_style']) && $setting['default_style']  ? $setting['default_style'] : 'default';
                    $defaultvalue = isset($setting['category_template']) && $setting['category_template']  ? $setting['category_template'] : '';
                    echo $defaultvalue ? Form::select_template($style, 'content', $defaultvalue, 'name=setting[category_template]', 'category') : '' ?>  
                </div>
            </div>
            <div class="control-group">
                <label class="control-label"><?php echo $this->_attributeLabels['list_template'] ?>：</label>
                <div class="controls listTemplate">
                    <?php 
                    $defaultvalue = isset($setting['list_template']) && $setting['list_template']  ? $setting['list_template'] : '';
                    echo $defaultvalue ? Form::select_template($style, 'content', $defaultvalue, 'name=setting[list_template]', 'list') : '' ?>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label"><?php echo $this->_attributeLabels['show_template'] ?>：</label>
                <div class="controls showTemplate">
                    <?php 
                    $defaultvalue = isset($setting['show_template']) && $setting['show_template']  ? $setting['show_template'] : '';
                    echo $defaultvalue ? Form::select_template($style, 'content', $defaultvalue, 'name=setting[show_template]', 'show') : '' ?> 
                </div>
            </div> 
        </div>
        <div id="p3" class="mt10">
            <div class="control-group">
                <label class="control-label"><?php echo $this->_attributeLabels['seo_title'] ?>：</label>
                <div class="controls">
                    <input type="text" value="<?php echo isset($setting['seo_title']) ? $setting['seo_title'] : '';  ?>" class="input-large" name="setting[seo_title]" />  
                </div>
            </div>
            <div class="control-group">
                <label class="control-label"><?php echo $this->_attributeLabels['seo_keyword'] ?>：</label>
                <div class="controls">
                    <input type="text" value="<?php echo isset($setting['seo_keyword']) ? $setting['seo_keyword'] : '';  ?>" class="input-large" name="setting[seo_keyword]" /> 
                </div>
            </div>
            <div class="control-group">
                <label class="control-label"><?php echo $this->_attributeLabels['seo_description'] ?>：</label>
                <div class="controls control-row-auto">
                    <textarea class="control-row4 input-large" name="setting[seo_description]"><?php echo isset($setting['seo_description']) ? $setting['seo_description'] : '';  ?></textarea>
                </div>
            </div>
        </div>
    </div>
    <div class="mt10">
        <input type="submit" value="提交" class="button" />
    </div>
    <?php $this->endWidget(); ?>
</div>